﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using BHXH_NT.Properties;

namespace BHXH_NT
{
    public partial class frmSetting : Form
    {
        public frmSetting()
        {
            InitializeComponent();
        }

        private void frmSetting_Load(object sender, EventArgs e)
        {
            flxSetting.Rows[1][1] = "DBName";
            flxSetting.Rows[2][1] = "DBName_Sothe";
            flxSetting.Rows[3][1] = "DBName_BHYT";
            flxSetting.Rows[4][1] = "DBName_Image";
            flxSetting.Rows[5][1] = "Server";
            flxSetting.Rows[6][1] = "User";
            flxSetting.Rows[7][1] = "Pass";
            flxSetting.Rows[8][1] = "M· TØnh";
            flxSetting.Rows[9][1] = "M· T¹m";
            flxSetting.Rows[10][1] = "C«ng Ty";
            flxSetting.Rows[11][1] = "§Þa ChØ";
            flxSetting.Rows[12][1] = "Thñ Tr­ëng";
            flxSetting.Rows[13][1] = "Qu¶n lý thÎ";
            flxSetting.Rows[14][1] = "nguoilap";

            flxSetting.Rows[1][2] = global::BHXH_NT.Properties.Settings.Default.DBName;
            flxSetting.Rows[2][2] = global::BHXH_NT.Properties.Settings.Default.DBName_Sothe;
            flxSetting.Rows[3][2] = global::BHXH_NT.Properties.Settings.Default.DBName_BHYT;
            flxSetting.Rows[4][2] = global::BHXH_NT.Properties.Settings.Default.DBName_Image;
            flxSetting.Rows[5][2] = global::BHXH_NT.Properties.Settings.Default.Server;
            flxSetting.Rows[6][2] = global::BHXH_NT.Properties.Settings.Default.User;
            flxSetting.Rows[7][2] = global::BHXH_NT.Properties.Settings.Default.Pass;
            flxSetting.Rows[8][2] = global::BHXH_NT.Properties.Settings.Default.MaTinh;
            flxSetting.Rows[9][2] = global::BHXH_NT.Properties.Settings.Default.MaTam;

            flxSetting.Rows[10][2] = global::BHXH_NT.Properties.Settings.Default.Congty;
            flxSetting.Rows[11][2] = global::BHXH_NT.Properties.Settings.Default.DiaChi;
            flxSetting.Rows[12][2] = global::BHXH_NT.Properties.Settings.Default.Thutruong;
            flxSetting.Rows[13][2] = global::BHXH_NT.Properties.Settings.Default.UserThe;
            flxSetting.Rows[14][2] = global::BHXH_NT.Properties.Settings.Default.Nguoilap;
         

         }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
         
               
            global::BHXH_NT.Properties.Settings.Default.DBName = flxSetting.Rows[1][2].ToString();
            global::BHXH_NT.Properties.Settings.Default.DBName_Sothe = flxSetting.Rows[2][2].ToString();
            global::BHXH_NT.Properties.Settings.Default.DBName_BHYT = flxSetting.Rows[3][2].ToString();
            global::BHXH_NT.Properties.Settings.Default.DBName_Image = flxSetting.Rows[4][2].ToString();
            global::BHXH_NT.Properties.Settings.Default.Server = flxSetting.Rows[5][2].ToString();
            global::BHXH_NT.Properties.Settings.Default.User = flxSetting.Rows[6][2].ToString();
            global::BHXH_NT.Properties.Settings.Default.Pass = flxSetting.Rows[7][2].ToString();
            global::BHXH_NT.Properties.Settings.Default.MaTinh = flxSetting.Rows[8][2].ToString();
            global::BHXH_NT.Properties.Settings.Default.MaTam  = flxSetting.Rows[9][2].ToString();

            global::BHXH_NT.Properties.Settings.Default.Congty = flxSetting.Rows[10][2].ToString();
            global::BHXH_NT.Properties.Settings.Default.DiaChi = flxSetting.Rows[11][2].ToString();
            global::BHXH_NT.Properties.Settings.Default.Thutruong = flxSetting.Rows[12][2].ToString();
            global::BHXH_NT.Properties.Settings.Default.UserThe  = flxSetting.Rows[13][2].ToString();
            global::BHXH_NT.Properties.Settings.Default.Nguoilap = flxSetting.Rows[14][2].ToString();

            global::BHXH_NT.Properties.Settings.Default.MISBHXH_NTConnectionString = "Data Source=" + Properties.Settings.Default.Server + ";"
            + "Initial Catalog=" + Properties.Settings.Default.DBName + ";" + "User ID=" + Properties.Settings.Default.User + ";"
            + "Password=" + Properties.Settings.Default.Pass;

            global::BHXH_NT.Properties.Settings.Default.MISBHXH_NTConnectionString1 = "Data Source=" + Properties.Settings.Default.Server + ";"
            + "Initial Catalog=" + Properties.Settings.Default.DBName_Sothe + ";" + "User ID=" + Properties.Settings.Default.User + ";"
            + "Password=" + Properties.Settings.Default.Pass;

            global::BHXH_NT.Properties.Settings.Default.MISBHXH_NTConnectionString2 = "Data Source=" + Properties.Settings.Default.Server + ";"
            + "Initial Catalog=" + Properties.Settings.Default.DBName_Image + ";" + "User ID=" + Properties.Settings.Default.User + ";"
            + "Password=" + Properties.Settings.Default.Pass;

            global::BHXH_NT.Properties.Settings.Default.MISBHXH_NTConnectionString3 = "Data Source=" + Properties.Settings.Default.Server + ";"
            + "Initial Catalog=" + Properties.Settings.Default.DBName_BHYT  + ";" + "User ID=" + Properties.Settings.Default.User + ";"
            + "Password=" + Properties.Settings.Default.Pass;

            if (ModuleBHXH.TestConnect() == false) { return; }         

            global::BHXH_NT.Properties.Settings.Default.Save();
            this.Close();
        }
    }
}
